package org.jeecg.modules.monitoringindicators.app.controller;


import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.jeecg.common.api.vo.Result;

import org.jeecg.modules.monitoringindicators.entity.FieldCropGrowthMonitoring;
import org.jeecg.modules.monitoringindicators.service.IFieldCropGrowthMonitoringService;


import lombok.extern.slf4j.Slf4j;


import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;

/**
 * @Description: 田块作物生长监测指标
 * @Author: Wenjl
 * @Date: 2022-02-09
 * @Version: V1.0
 */
@Api(tags = "田块作物生长监测指标")
@RestController
@RequestMapping("/app/monitoringindicators/fieldCropGrowthMonitoring")
@Slf4j
public class AppFieldCropGrowthMonitoringController extends JeecgController<FieldCropGrowthMonitoring, IFieldCropGrowthMonitoringService> {
    @Autowired
    private IFieldCropGrowthMonitoringService fieldCropGrowthMonitoringService;
    /**
     * 用来判断用户是否有权限访问添加页面
     *
     * @return
     */
    @RequiresPermissions({"fieldCropGrowthMonitoring"})
    @PostMapping(value = "/toAdd")
    public Result<?> toAdd() {

        return Result.OK("true");
    }
    /**
     * 列表查询
     *
     * @return
     */
    @RequiresPermissions({"fieldCropGrowthMonitoring"})
    @AutoLog(value = "田块作物生长监测指标-分页列表查询")
    @ApiOperation(value = "田块作物生长监测指标-分页列表查询", notes = "田块作物生长监测指标-分页列表查询")
    @GetMapping(value = "/list")
    public Result<?> queryPageList() {
        List<FieldCropGrowthMonitoring> list = fieldCropGrowthMonitoringService.list();
        return Result.OK(list);
    }

    /**
     * 添加
     *
     * @param fieldCropGrowthMonitoring
     * @return
     */
    @AutoLog(value = "田块作物生长监测指标-添加")
    @ApiOperation(value = "田块作物生长监测指标-添加", notes = "田块作物生长监测指标-添加")
    @PostMapping(value = "/add")
    public Result<?> add(@RequestBody FieldCropGrowthMonitoring fieldCropGrowthMonitoring) {
        fieldCropGrowthMonitoringService.save(fieldCropGrowthMonitoring);
        return Result.OK("添加成功！");
    }

    /**
     * 编辑
     *
     * @param fieldCropGrowthMonitoring
     * @return
     */
    @AutoLog(value = "田块作物生长监测指标-编辑")
    @ApiOperation(value = "田块作物生长监测指标-编辑", notes = "田块作物生长监测指标-编辑")
    @PutMapping(value = "/edit")
    public Result<?> edit(@RequestBody FieldCropGrowthMonitoring fieldCropGrowthMonitoring) {
        fieldCropGrowthMonitoringService.updateById(fieldCropGrowthMonitoring);
        return Result.OK("编辑成功!");
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "田块作物生长监测指标-通过id删除")
    @ApiOperation(value = "田块作物生长监测指标-通过id删除", notes = "田块作物生长监测指标-通过id删除")
    @PostMapping(value = "/delete/{id}")
    public Result<?> delete(@PathVariable(value = "id") String id) {
        fieldCropGrowthMonitoringService.removeById(id);
        return Result.OK("删除成功!");
    }


    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @AutoLog(value = "田块作物生长监测指标-通过id查询")
    @ApiOperation(value = "田块作物生长监测指标-通过id查询", notes = "田块作物生长监测指标-通过id查询")
    @GetMapping(value = "/queryById/{id}")
    public Result<?> queryById(@PathVariable(value = "id") String id) {
        FieldCropGrowthMonitoring fieldCropGrowthMonitoring = fieldCropGrowthMonitoringService.getById(id);
        if (fieldCropGrowthMonitoring == null) {
            return Result.error("未找到对应数据");
        }
     
        return Result.OK(fieldCropGrowthMonitoring);
    }


}
